﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.windows.restricted {
    import flash.events.*;
    import flash.display.*;
    import net.wooga.pets.views.windows.*;
    import net.wooga.pets.models.windows.builders.vo.*;
    import reprise.tweens.*;
    import net.wooga.pets.models.windows.builders.config.texts.*;
    import flash.errors.*;

    public class BaseWindowView extends Sprite implements IWindowView {

        private var _id:int;
        private var _text:IWindowsTextVo;
        private var _options:IWindowOptions;
        private var fadeTween:SimpleTween;

        public function build(_arg1:IWindowOptions):void{
            this.verifyVo(_arg1);
            this._options = _arg1;
            this._text = _arg1.textValues;
        }
        private function verifyVo(_arg1:IWindowOptions):void{
            if (_arg1 == null){
                throw (new IllegalOperationError("The supplied argument IWindowsBuildVO is null"));
            };
        }
        public function onAddedToStage():void{
            this.runAutoClose();
        }
        public function onRemovedFromStage():void{
            this.destroy();
        }
        private function runAutoClose():void{
            if (this.options.autoClose){
                this.options.autoClose.run(this.close);
            };
        }
        private function interruptAutoClose():void{
            if (this.options.autoClose){
                this.options.autoClose.interrupt();
            };
        }
        protected function dispatchToMediator(_arg1:String):void{
            this.dispatchEvent(new Event(_arg1, true));
        }
        public function get options():IWindowOptions{
            return (this._options);
        }
        public function set id(_arg1:int):void{
            this._id = _arg1;
        }
        public function get id():int{
            return (this._id);
        }
        public function close():void{
            this.interruptAutoClose();
            this.dispatchCloseToViewMediator();
        }
        private function dispatchCloseToViewMediator():void{
            this.dispatchEvent(new Event(Event.CLOSE));
        }
        public function remove():void{
            this.interruptAutoClose();
            if (this.options.fadeOutDelay){
                this.fadeTween = new SimpleTween();
                this.fadeTween.setDuration(this.options.fadeOutDelay);
                this.fadeTween.addTweenProperty((this as Sprite), "alpha", 1, 0);
                this.fadeTween.addEventListener(Event.COMPLETE, this.onFadeTweenEnded);
                this.fadeTween.execute();
            } else {
                this.removeFromStage();
            };
        }
        protected function centerInStage():void{
            this.x = ((this.stage.stageWidth - width) >> 1);
            this.y = ((this.stage.stageHeight - height) >> 1);
        }
        private function onFadeTweenEnded(_arg1:Event):void{
            this.fadeTween.removeEventListener(Event.COMPLETE, this.onFadeTweenEnded);
            this.fadeTween = null;
            this.removeFromStage();
        }
        private function removeFromStage():void{
            this.parent.removeChild(this);
        }
        private function destroy():void{
            this._options.destroy();
            this._options = null;
            this._text = null;
        }

    }
}//package net.wooga.pets.views.windows.restricted 
